/**
 * @author        Nicolas Bottarini <nicolasbottarini@gmail.com>, 404 <http://www.proyecto404.com>
 * @version       $Rev: 3 $
 * @lastrevision  $Date: 2011-09-12 16:45:37 +0000 (Mon, 12 Sep 2011) $	 
 */
package com.proyecto404.core.configuration {
	import com.proyecto404.core.collections.Dictionary;
	import com.proyecto404.core.collections.IIterator;
	import com.proyecto404.core.exception.InvalidOperationException;

	public class DictionaryConfigurationHandler extends ConfigurationHandler	{
		private var _data:Dictionary;
		
		public function DictionaryConfigurationHandler(name:String) {
			super(name);
			
			_data = new Dictionary();
		}
		
		public override function addConfigurations(xmlData:XML):void {
			for each(var node:XML in xmlData.children()) {
				var name:String = node.name().toString();
				switch(name) {
					case "add":
						_data.add((node.@key).toString(), (node.@value).toString());
						break;
					case "remove":
						_data.removeKey((node.@key).toString());
						break;
					case "clear":
						_data.clear();
						break;
					default:
						throw new InvalidOperationException("Invalid node: " + name);
						break;
				}
			}
		}
		
		public override function get(configuration:String):* { 
			return _data.get(configuration) as String;
		}

		public override function contains(configuration:String):Boolean {
			return _data.containsKey(configuration);
		}
		
		public override function getConfigurations():IIterator {
			return _data.getIterator();
		}
	}
}